<?php

namespace Portal\MessageBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class MessageType extends AbstractType
{
    protected $receiverId;
    protected $receiverRole;
    
    public function __construct($receiverId, $receiverRole)
    {
      $this->receiverId = $receiverId;
      $this->receiverRole = $receiverRole;
    }
  
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder            
            ->add('title')
            ->add('body', 'textarea')
            ->add('subjectCategory', 'entity', array('class' => 'Portal\MessageBundle\Entity\SubjectCategory', 'property' => 'name'))
            ->add('subject', 'entity', array('class' => 'Portal\MessageBundle\Entity\Subject', 'property' => 'name'))
            ->add('firstName')
            ->add('lastName')
            ->add('phone')
            ->add('email','email')
            ->add('location', 'entity', array('class' => 'Portal\MessageBundle\Entity\Location', 'property' => 'name'))
            ->add('receiverId', 'hidden', array('data'=> $this->receiverId))
            ->add('receiverRole', 'hidden', array('data' => $this->receiverRole))
        ;
    }

    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'Portal\MessageBundle\Entity\Message'
        ));
    }

    public function getName()
    {
        return 'portal_messagebundle_messagetype';
    }
}
